*******************************************************
**Figure 1: Changes in Republican Two-Party Vote Share
*******************************************************

use BFW_IO, clear

*ssc install maptile (also requires geographic template `county2014' available here: https://michaelstepner.com/maptile/geographies/
maptile rep_change_2016 , geo(county2014) conus stateoutline(thin)  legdecimals(2) 


*********************************************
**Figure 2: Manufacturing Shares by Country
*********************************************

use BFW_manufacturing_shares, clear
encode country, gen(id1)
xtline MFG_Share, t(year) i(id1) overlay ytitle(Manufacturing (% of Total Employment), size(medsmall)) ///
	graphregion(color(white)) legend(off) 


*******************************************************
**Figure 3: MFN Emp 1970 and recent outcome, by county
*******************************************************
use BFW_IO, clear

twoway (scatter manuf_empl_sh_chg_0015  bea_manuf_empl_sh_1970 , msize(vsmall)) ///
	(lfit manuf_empl_sh_chg_0015  bea_manuf_empl_sh_1970  ), ///
	ytitle(Change in MFG Employment Share 2000-2015, size(medlarge)) xtitle(Manufacturing Employment Share (1970), size(medlarge)) yscale(range(-60  40)) ylabel(-60(20)40) graphregion(color(white)) legend(off)

graph save s1, replace

twoway (scatter lfp_chg_0015 bea_manuf_empl_sh_1970 if lfp_chg_0015<40, msize(vsmall)) ///
	(lfit lfp_chg_0015  bea_manuf_empl_sh_1970 if lfp_chg_0015<40 ), ///
	ytitle(Change in Labor Force Participation Rate 2000-2015, size(medlarge)) xtitle(Manufacturing Employment Share (1970), size(medlarge)) yscale(range(-60  40)) ylabel(-60(20)40) graphregion(color(white)) legend(off)

	graph save s2, replace

twoway (scatter median_hh_inc_pctchg_0015  bea_manuf_empl_sh_1970 if median_hh_inc_pctchg_0015<100, msize(vsmall)  ) ///
	(lfit median_hh_inc_pctchg_0015  bea_manuf_empl_sh_1970  if median_hh_inc_pctchg_0015<100), ///
	ytitle(Change in Median Household Income 2000-2015 (%), size(medlarge)) xtitle(Manufacturing Employment Share (1970), size(medlarge)) graphregion(color(white)) legend(off)

	graph save s3, replace
graph combine s1.gph s2.gph  s3.gph   ,  xcommon rows(1) graphregion(margin(zero) ) ysize(2)


**********************************************
**Figure 4
**********************************************
*See R File


*************************************************
**Figure 5: Business Services Employment Shares
*************************************************
use BFW_IO, clear
maptile bus_empl_sh_2015, geo(county2014) conus stateoutline(thin) 


*************************************************
**Figure 6: Scatterplots of Trump Support
*************************************************
use BFW_IO, clear
twoway (scatter trumpvromney  chg_logpop0015 , msize(vsmall))(lfit trumpvromney  chg_logpop0015), xtitle("Change in log Population, 2000-2015") legend(off) graphregion(fcolor(white)) saving(pop, replace) 
twoway (scatter trumpvromney  median_hh_inc_chg_0015, msize(vsmall))(lfit trumpvromney  median_hh_inc_chg_0015), xtitle("Change in Median Household Income, 2000-2015") legend(off) graphregion(fcolor(white)) saving(inc, replace)
twoway (scatter trumpvromney  mort_risk_age2545_pctchg_0014, msize(vsmall))(lfit trumpvromney  mort_risk_age2545_pctchg_0014), xtitle("Change in Mortality Risk (%), 2000-2014") legend(off) graphregion(fcolor(white)) saving(mort, replace)
gen rust = 0
replace rust = 1 if state == "Michigan"  |state == "Wisconsin" |state =="Indiana" |state== "Illinois" |state == "Ohio" |state== "Pennsylvania"
twoway (scatter trumpvromney  chg_logpop0015 if rust ==1, msize(vsmall))(lfit trumpvromney  chg_logpop0015 if rust ==1), xtitle("Change in log Population, 2000-2015") legend(off) graphregion(fcolor(white)) saving(pop_r, replace) 
twoway (scatter trumpvromney  median_hh_inc_chg_0015 if rust ==1, msize(vsmall))(lfit trumpvromney  median_hh_inc_chg_0015 if rust ==1), xtitle("Change in Median Household Income, 2000-2015") legend(off) graphregion(fcolor(white)) saving(inc_r, replace)
twoway (scatter trumpvromney  mort_risk_age2545_pctchg_0014 if rust ==1, msize(vsmall))(lfit trumpvromney  mort_risk_age2545_pctchg_0014 if rust ==1), xtitle("Change in Mortality Risk (%), 2000-2014") legend(off) graphregion(fcolor(white)) saving(mort_r, replace)
gr combine inc.gph pop.gph  mort.gph inc_r.gph pop_r.gph  mort_r.gph, rows(2) graphregion(margin(zero)) ysize(2)


*********************************************
**Figure 7: Election model AV Plot
*********************************************
use BFW_IO, clear
quietly: reg trumpvromney    age_65_plus_15 race1_15  hispanic_15 ln_wage female_15 college_15 logpop2015 bus_empl_sh_2015  china_ct_us_0015 mfg_loss_7015  [aw= pop2000 ]  ,  ro
reg trumpvromney    age_65_plus_15 race1_15  hispanic_15 ln_wage female_15 college_15 logpop2015 bus_empl_sh_2015  mfg_loss_7015 if e(sample) [aw= pop2000 ]  ,  ro
avplot mfg_loss_7015,  ytitle("Trump (2016) Compared to Romney (2012) | Controls") xtitle("Decline in Manufacturing Employment | Controls")  msize(vsmall) graphregion(color(white)) legend(off)


*******************************************************************
**Figure 8: Manufacturing Job Losses and Post-Crisis Unemployment
*******************************************************************
use BFW_IO, clear

twoway (scatter unemp_10_15 mfg_loss_7015, msize(vsmall)  ) ///   
	(lfit unemp_10_15 mfg_loss_7015 ), ///
	ytitle(Avg. Unemployment (2010-2015), size(medlarge)) xtitle(Decline in MFG Empl. Share (1970 vs 2015), size(medlarge)) graphregion(color(white)) legend(off)
	

*********************************************************************************
**Appendix Material: Table A1, Figure A1, Figure A2: Election Models and Figures
*********************************************************************************
use BFW_IO, clear
eststo clear
quietly: reg trumpvromney    age_65_plus_15 race1_15  hispanic_15 ln_wage female_15 college_15 logpop2015 bus_empl_sh_2015  china_ct_us_0015 mfg_loss_7015  [aw= pop2000 ]  ,  ro
eststo: reg trumpvromney    age_65_plus_15 race1_15  hispanic_15 ln_wage female_15 college_15 logpop2015 bus_empl_sh_2015  mfg_loss_7015 if e(sample) [aw= pop2000 ]  ,  ro
****Figure A1
avplot bus_empl_sh_2015, ytitle("Trump (2016) Compared to Romney (2012) | Controls") xtitle("Business Services Employment | Controls") msize(vsmall) note("coef = -.226, (robust) se = .048, t = -4.67") graphregion(color(white)) legend(off)
eststo: reg trumpvromney    age_65_plus_15 race1_15  hispanic_15 ln_wage female_15 college_15 logpop2015 bus_empl_sh_2015  mfg_loss_7015 china_ct_us_0015 if e(sample) [aw= pop2000 ]  ,  ro
eststo: reg trumpvromney    age_65_plus_15 race1_15  hispanic_15 ln_wage female_15 college_15 logpop2015 bus_empl_sh_2015  c.unemp_10_15 c.mfg_loss_7015 if e(sample) [aw= pop2000 ] , ro
eststo: reg trumpvromney    age_65_plus_15 race1_15  hispanic_15 ln_wage female_15 college_15 logpop2015 bus_empl_sh_2015  c.unemp_10_15##c.mfg_loss_7015 if e(sample) [aw= pop2000 ]  ,  ro
****Figure A2
margins, dydx(unemp_10_15) at( mfg_loss_7015=(-25(5)60))
marginsplot, title("") ytitle("Estimated Effect of Avg. Unemployment (2010-2015)") recast(line) recastci(rline) ciopts(lpattern(shortdash))  ///
	xsc(titlegap(5)) ysc(titlegap(5)) scheme(s2color) graphregion(color(white)) xtitle("Decline in MFG Empl. Share (1970 vs 2015)") ///
	legend(off) yline	(0) addplot(hist mfg_loss_7015 if e(sample)   , width(1) percent mfcolor(none) ///
	fcolor(none) lcolor(gs10) yaxis(2) yscale(alt axis(2)))

esttab * using tableA1n.csv,   label b(3) se(3) r2(3) scalar( N_clust) sfmt( a0) star(* 0.1 ** 0.05 *** 0.01) replace


***************************************************************************************************************************************************



